package cc.comac.mom.datahandlers.entity;

import java.util.HashMap;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cc.comac.mom.bean.QualityQarProblemForm;
import cc.comac.mom.dao.entity.QualityQarProblemFormDao;
import cc.comac.mom.entity.QualityQarProblemFormEntity;
import cc.comac.mom.util.BaseEntityDataUtil;
import cc.comac.mom.util.ResultBean;
@Transactional
@Component
public class QualityQarProblemFormDataHandler extends ServiceImpl<QualityQarProblemFormDao, QualityQarProblemFormEntity>{
	
	@Autowired
	private QualityQarProblemFormDao qualityQarProblemFormDao;
	
	@Autowired
	private BaseEntityDataUtil baseEntityDataUtil;
	
	public HashMap<String,String> insertQarProblemForm(QualityQarProblemForm qualityQarProblemForm) {
		HashMap<String,String> hashMap = new HashMap<String, String>();
		hashMap.put("uapNo", "");
		hashMap.put("status", "1");
		hashMap.put("msg", "");
		QualityQarProblemFormEntity innerData = qualityQarProblemForm.getInnerData();
		if (StringUtils.isEmpty(innerData.getQarNo())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "qar编号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getMaterialCode())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "物料编号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getSerialNum())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "序列号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getBatch())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "批次号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getSupplier())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "供应商不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getVer())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "版次不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getPurchaseOrder())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "采购订单编号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getDeviationProcess())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "偏差过程不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getSapBatch())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "SAP批次号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getMigoNo())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "内向交货单号不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getInspect())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "检验人员不能为空！");
			return hashMap;
		}
		if (StringUtils.isEmpty(innerData.getInspectDate())) {
			hashMap.put("status", "0");
			hashMap.put("msg", "检验时间不能为空！");
			return hashMap;
		}
		baseEntityDataUtil.setBaseEntityData(innerData);
		qualityQarProblemFormDao.insert(innerData);
		return hashMap;
	}
	// 1、	当QAR任务需要开立问题单时，QAR系统将该任务信息发送给问题单系统，
	public ResultBean sendQualityOrder (String qarNo) {
		return null;
	}

}
